package ldh.fx.adminfx.controller;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import ldh.fx.adminfx.pojo.Activity;
import org.kordamp.ikonli.fontawesome.FontAwesome;
import org.kordamp.ikonli.javafx.FontIcon;

import java.net.URL;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

public class ActivityController implements Initializable {

    @FXML private VBox activityVBox;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        List<Activity> activities = loadActivityList();
        for(Activity activity : activities) {
            this.activityVBox.getChildren().add(createItem(activity));
        }
    }

    private Node createItem(Activity activity) {
        GridPane gridPane = new GridPane();
        gridPane.getStyleClass().add("list-node");
        FontIcon fontIcon1 = FontIcon.of(FontAwesome.findByDescription(activity.getIconDescription()), 20, Color.WHITE);
        Label iconLabel = new Label();
        iconLabel.getStyleClass().add("icon-label");
        iconLabel.setGraphic(fontIcon1);

        TextField title = new TextField(activity.getTitle());
        title.setEditable(false);
        title.getStyleClass().add("title-label");
        TextField subTitle = new TextField(activity.getSubTitle());
        subTitle.setEditable(false);
        subTitle.getStyleClass().add("subtitle-label");
        gridPane.getChildren().addAll(iconLabel, title, subTitle);
        int row =0, col=0;
        GridPane.setConstraints(iconLabel, col++, row, 1, 2);
        GridPane.setConstraints(title, col, row++, 2, 1);
        GridPane.setConstraints(subTitle, col, row, 1, 1);
        return gridPane;
    }

    private List<Activity> loadActivityList() {
        List<Activity> activities = new ArrayList();
        for(int i=0; i<10; i++) {
            Activity activity = new Activity();
            activity.setIconDescription(FontAwesome.SEARCH.getDescription());
            activity.setTitle("demo " + i);
            activity.setSubTitle("sub demo "+ i);
            activity.setLocalDateTime(LocalDateTime.now());

            activities.add(activity);
        }
        return activities;
    }
}
